﻿///////////////////////////////////////////////////////////////////////////////
//
// This file is part of the BassDrop project
//   https://code.google.com/p/bass-drop/
//
//
// Creator:	Gergely Krajcsovszki (krajcsovszkig@hotmail.com)
// Date:	2014-04-19 13:20
//
//
// Copyright © 2013-2014. Gergely Krajcsovszki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
///////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BassDrop.Core.Common.Localization;
using BassDrop.Core.Common.Options;
using BassDrop.Core.Common.Options.Items;
using BassDrop.Core.Common.Services;
using BassDrop.Core.Common.Utilities;
using BassDrop.DesktopClient.UI.Panels;

namespace BassDrop.DesktopClient.Options.OptionsSets
{
	/// <summary>
	/// Class containing the playlist display options items
	/// </summary>
	public class PlaylistDisplayOptionsSet : OptionsSetBase
	{
		/// <summary>
		/// The name of this options set
		/// </summary>
		public override string Name
		{
			get
			{
				return Strings.LabelSettingsViewTreeViewItemPlaylistDisplay;
			}
		}

		private BooleanPropertyOptionsItem m_expandDetailsOnSelectOptionsItem;

		/// <summary>
		/// Constructs a new playlist display options set
		/// </summary>
		public PlaylistDisplayOptionsSet()
		{
			m_expandDetailsOnSelectOptionsItem = new BooleanPropertyOptionsItem(
				SetExpandDetailsOnSelect,
				GetExpandDetailsOnSelect,
				Strings.LabelOptionsSetDisplayOptionsExpandDetailsOnSelect,
				null );

			OptionList.Add( m_expandDetailsOnSelectOptionsItem );

			Strings.StaticPropertyChanged += Strings_StaticPropertyChanged;
			PlaylistPanel.StaticPropertyChanged += PlaylistPanel_StaticPropertyChanged;
		}

		private bool GetExpandDetailsOnSelect()
		{
			return PlaylistPanel.ExpandDetailsOnSelect;
		}

		private void SetExpandDetailsOnSelect( bool value )
		{
			PlaylistPanel.ExpandDetailsOnSelect = value;
		}

		/// <summary>
		/// Loads the options
		/// </summary>
		/// <param name="settings">the seettings object to load from</param>
		public override Task Load( ISettings settings )
		{
			if ( !String.IsNullOrEmpty( settings.SettingAt( "ExpandDetailsOnSelect" ) ) )
			{
				SetExpandDetailsOnSelect( bool.Parse( settings.SettingAt( "ExpandDetailsOnSelect" ) ) );
			}

			return ThreadingUtils.CompletedTask();
		}

		/// <summary>
		/// Saves the options
		/// </summary>
		/// <param name="settings">the seettings object to save to</param>
		public override void Save( ISettings settings )
		{
			settings.SetSettingAt( "ExpandDetailsOnSelect", GetExpandDetailsOnSelect().ToString() );
		}

		private void Strings_StaticPropertyChanged( object sender, PropertyChangedEventArgs e )
		{
			if ( e.PropertyName == "LabelSettingsViewTreeViewItemPlaylistDisplay" )
			{
				OnPropertyChanged( new PropertyChangedEventArgs( "Name" ) );
			}
			else if ( e.PropertyName == "LabelOptionsSetDisplayOptionsExpandDetailsOnSelect" )
			{
				m_expandDetailsOnSelectOptionsItem.Name = Strings.LabelOptionsSetDisplayOptionsExpandDetailsOnSelect;
			}
		}

		private void PlaylistPanel_StaticPropertyChanged( object sender, PropertyChangedEventArgs e )
		{
			OnPropertyChanged( new PropertyChangedEventArgs( e.PropertyName ) );
		}
	}
}
